package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.IntoSet;
import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.dto.FanEntityDto;
import c.x.jy.dao.entity.FanEntity;
import c.x.jy.service.service.FanService;
import c.x.jy.service.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 大师粉丝表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-25 10:46:12
 */

@RestController
@RequestMapping("wechat/fan")
public class FanController {
    @Autowired
    private FanService fanService;
    @Autowired
    private MemberService memberService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fanService.queryPage(params);

        return R.put(page);
    }
    //查询当前用户是否已关注指定的专家
    @Login
    @RequestMapping("/queryinfo")
     public R queryinfo(Long teacherId){
        Long fanid = memberService.getCurrUser().getId();
        FanEntity fanEntity = fanService.queryinfo(teacherId,fanid);

        return R.put(fanEntity);
    }
    //取消关注

    @Login
    @RequestMapping("/CancelGZ")
    public R CancelGZ(Long teacherId){
        Long fanid = memberService.getCurrUser().getId();
        fanService.CancelGZ(teacherId,fanid);

        return R.ok();
    }
    //我的人脉
    @IntoSet(Includefields={"fanName","fanImage","teacherName","teacherImage"})
    @Login
    @RequestMapping("/myRenmai")
    public R myRenmai(){
        List<FanEntityDto> list = (List<FanEntityDto>) fanService.myRenmai();

        return R.put(list);
    }
    //我的关注
    @IntoSet(Includefields={"fanName","fanImage","teacherName","teacherImage"})
    @Login
    @RequestMapping("/myGuanzhu")
    public R myGuanzhu(){
        List<FanEntityDto> list = (List<FanEntityDto>) fanService.myGuanzhu();

        return R.put(list);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{fanId}")
    public R info(@PathVariable("fanId") Integer fanId){
		FanEntity fan = fanService.getById(fanId);

        return R.put(fan);
    }

    /**
     * 保存
     */
    @Login
    @RequestMapping("/save")
    public R save(@RequestBody FanEntity fan){
        Long fanid = memberService.getCurrUser().getId();
        fan.setFanId(fanid);
		fanService.save(fan);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FanEntity fan){
		fanService.updateById(fan);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value="/delete/{fanId}" ,method = RequestMethod.DELETE)
    public R delete(@PathVariable("fanId") Integer fanId){
		fanService.removeByIds(Arrays.asList(fanId));

        return R.ok();
    }

}

